using System.IO;
using System.Web.UI;
using System.Web.UI.Design;
using System.Web.UI.HtmlControls;

namespace Library.WebControls.SimpleTreeView {
	public class SpTreeViewDesign : ControlDesigner {
		public override string GetDesignTimeHtml() {
			var tv = (SpTreeView)Component;
			
			var sw = new StringWriter();
			var html = new HtmlTextWriter(sw);
			tv.CreateCssLink().RenderControl(html);
			var div = new HtmlGenericControl("div");
			var ul = new HtmlGenericControl("ul");
			div.Controls.Add(ul);
			ul.Attributes["class"] = "sptreeview";
			ul.Attributes["root"] = "true";
			for (int i = 1; i <= 5; i++) {
				var li = new HtmlGenericControl("li");
				li.Attributes["class"] = "tvitem";
				ul.Controls.Add(li);

				var divTitle = new HtmlGenericControl("div");
				divTitle.Attributes["class"] = "tvtitle";
				li.Controls.Add(divTitle);
				var spanExpend = new HtmlGenericControl("span");
				divTitle.Controls.Add(spanExpend);
				spanExpend.Attributes["class"] = "tvexpend";

				var spanText = new HtmlGenericControl("span");
				divTitle.Controls.Add(spanText);
				spanText.InnerText = "Treeview item " + (i);
			}

			div.RenderControl(html);


			return sw.ToString();
		}
	}
}